package chat.ui;

import java.util.Date;

import javax.swing.JTextArea;

public class ChatHandler implements Runnable {
	
	
	public ChatHandler(){
		
		new DateForMessages();
	}
	
	@Override
	public void run(){
		
	}
	
	public static ChatPanel setTextFromMessage(String text, ChatPanel area){
		
		String t = area.getChatText();
		String new_text;
		
		if (!t.equalsIgnoreCase("")){
				new_text = t + "\n" + DateForMessages.getCurrentDateFromMessage() +" "+ text;
		}
		else {
			new_text = DateForMessages.getCurrentDateFromMessage() +" "+ text;
		}
		
		area.setChatText(new_text);
		
		return area; 
	}
	
	private static class DateForMessages {
		
		public DateForMessages(){
			
			c_date = new Date();
			date_hour = c_date.getHours();
			date_minutes = c_date.getMinutes();
			
			date_year = 1900 + c_date.getYear();
			date_month = c_date.getMonth();
			date_day = c_date.getDate();
			
		}
		
		public static String getCurrentDateFromMessage() {
			
			date1 = date_day+"/"+date_month+"/"+date_year+" "+date_hour+":"+date_minutes;
			
			return date1;
		}
		private static int date_hour, date_minutes, date_year, date_month, date_seconds, date_month_number, date_day;
		private static String date1;
		Date c_date;
	}
	
}
